package com.meta.builder.schema.rule;

import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JDocComment;
import com.sun.codemodel.JDocCommentable;
import com.sun.codemodel.JFieldVar;
import org.jsonschema2pojo.*;
import org.jsonschema2pojo.rules.*;
import org.jsonschema2pojo.util.NameHelper;
import org.jsonschema2pojo.util.ReflectionHelper;

public class MetaRuleFactory extends RuleFactory {
    private RuleLogger logger;
    private NameHelper nameHelper;
    private ReflectionHelper reflectionHelper;
    private GenerationConfig generationConfig;
    private Annotator annotator;
    private SchemaStore schemaStore;

    public MetaRuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) {
        this.generationConfig = generationConfig;
        this.annotator = annotator;
        this.schemaStore = schemaStore;
        this.nameHelper = new NameHelper(generationConfig);
        this.reflectionHelper = new ReflectionHelper(this);
    }

    public MetaRuleFactory() {
        this(new DefaultGenerationConfig(), new Jackson2Annotator(new DefaultGenerationConfig()), new SchemaStore());
    }


    public Rule<JDefinedClass, JDefinedClass> getPropertyRule() {
        return new MetaPropertyRule(this);
    }


    public Rule<JFieldVar, JFieldVar> getDefaultRule() {
        return new DefaultRule(this);
    }


    public Rule<JFieldVar, JFieldVar> getPatternRule() {
        return new PatternRule(this);
    }

    public Rule<JFieldVar, JFieldVar> getValidRule() {
        return new ValidRule(this);
    }

    public GenerationConfig getGenerationConfig() {
        return this.generationConfig;
    }

    public void setGenerationConfig(GenerationConfig generationConfig) {
        this.generationConfig = generationConfig;
        this.nameHelper = new NameHelper(generationConfig);
    }

    public Annotator getAnnotator() {
        return this.annotator;
    }

    public void setAnnotator(Annotator annotator) {
        this.annotator = annotator;
    }

    public RuleLogger getLogger() {
        return this.logger;
    }

    public void setLogger(RuleLogger logger) {
        this.logger = logger;
    }

    public SchemaStore getSchemaStore() {
        return this.schemaStore;
    }

    public void setSchemaStore(SchemaStore schemaStore) {
        this.schemaStore = schemaStore;
    }

    public NameHelper getNameHelper() {
        return this.nameHelper;
    }

    public ReflectionHelper getReflectionHelper() {
        return this.reflectionHelper;
    }

    public Rule<JDefinedClass, JDefinedClass> getDynamicPropertiesRule() {
        return new DynamicPropertiesRule(this);
    }

    public Rule<JDocCommentable, JDocComment> getJavaNameRule() {
        return new JavaNameRule();
    }
}
